package com.example.mall.order.service.impl;

import com.alibaba.fastjson2.JSON;
import com.example.mall.order.entity.OrderEntity;
import com.rabbitmq.client.Channel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Service;

import java.io.IOException;

@Service("rabbitMqService")
@Slf4j
public class RabbitMqServiceImpl {

    @RabbitListener(queues = {"main.queue"})
    public void receiveMainQueue(Message message, OrderEntity orderEntity, Channel channel) throws IOException {
        log.info("接受到[main.queue]队列消息[message]：{}", message);
        log.info("接受到[main.queue]队列消息[OrderEntity]：{}", JSON.toJSONString(orderEntity));
        log.info("接受到[main.queue]队列消息[channel]：{}", channel);
        channel.basicAck(message.getMessageProperties().getDeliveryTag(), false);
    }

}
